﻿using System;
using System.Windows.Forms;

namespace ALDIOrganizer
{
    public partial class AddRowToTemplate : Form
    {
        public StaffRole Result;

        public AddRowToTemplate()
        {
            InitializeComponent();
        }

        private void formAddEmpToTemplate_Load(object sender, EventArgs e)
        {
            lbRoles.DataSource = DataGridViewOpeningHrs.GetOptionsForAddAnother;
            lbRoles.DisplayMember = "PositionName";
            if (lbRoles.Items.Count < 1)
            {
                return;
            }
            lbRoles.SelectedIndex =
                MainForm.lastUsedAddEmpToTemp >= 0 ?
                MainForm.lastUsedAddEmpToTemp :
                0;
        }

        private void lbRoles_SelectedIndexChanged(object sender, EventArgs e)
        {
            Result = (StaffRole)lbRoles.SelectedValue;
            lbxDefinition.Text = Result.PositionExplanation;
        }

        private void lbRoles_DoubleClick(object sender, EventArgs e)
        {
            MainForm.lastUsedAddEmpToTemp = lbRoles.SelectedIndex;

            DialogResult = DialogResult.OK;
            Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            MainForm.lastUsedAddEmpToTemp = lbRoles.SelectedIndex;
        }
    }
}
